package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;

import pojo.Area;
import dao.AreaDao;
import dao.impl.AreaDaoImpl;

public class SearchAreasServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private AreaDao areaDao = new AreaDaoImpl();

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		
		String keyword = request.getParameter("kw");
		List<Area> areas = null;
		if (keyword != null && !keyword.isEmpty()) {
			areas = areaDao.findByKeyword(keyword);
		}
		ObjectMapper mapper = new ObjectMapper();
		mapper.writeValue(response.getWriter(), areas);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
